package com.xuecheng.comment.controller;

import com.xuecheng.api.comment.CommentApi;
import com.xuecheng.api.comment.model.*;
import com.xuecheng.api.comment.model.dto.CommentDTO;
import com.xuecheng.api.comment.model.dto.ReplyDTO;
import com.xuecheng.comment.service.CommentService;
import com.xuecheng.common.domain.page.PageRequestParams;
import com.xuecheng.common.domain.page.PageVO;
import com.xuecheng.common.domain.response.RestResponse;
import com.xuecheng.common.domain.uaa.LoginUser;
import com.xuecheng.common.enums.common.USEEnum;
import org.springframework.web.bind.annotation.*;
import com.xuecheng.comment.service.CommentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author itcast
 */
@Slf4j
@RestController
public class CommentController {

    @Autowired
    private CommentService commentService;

    /**
     * 远程调用接口 ，查询 评论
     *
     * @param model
     * @return
     */
    @PostMapping("l/course-comment/creatComment")
    public RestResponse<CommentDTO> createComment(@RequestBody CommentModel model) {
        System.out.println("model = " + model);

        CommentDTO commentDTO = commentService.createComment(model);

        return RestResponse.success(commentDTO);
    }

    /**
     * 远程调用接口 评论列表，门户页面 查询
     *
     * @param model
     * @return
     */
    @PostMapping("l/course-comment/querryComment")
    public RestResponse<PageVO<CommentDTO>> querryCommentList(@RequestBody QuerryCommentModel model) {

        PageVO<CommentDTO> pageVO = commentService.querryCommentList(model, USEEnum.USE_PORTAL.getCode());

        return RestResponse.success(pageVO);
    }

    /**
     * 远程调用接口 ，课程评论数据统计
     *
     * @param targetId
     * @return
     */
    @GetMapping("l/course-comment/course-statistics/{targetId}")
    RestResponse<CommentStaticsModel> commentStatistics(@PathVariable(value = "targetId") Long targetId) {

        CommentStaticsModel staticsModel = commentService.commentStatistics(targetId);

        return RestResponse.success(staticsModel);
    }

    /**
     * 课程点赞
     *
     * @param commentId
     * @param userName
     * @return
     */
    @PostMapping("l/course-comment/praise/{commentId}")
    Boolean praiseComment(@PathVariable(value = "commentId") Long commentId, String userName) {
        Boolean result = commentService.praiseComment(commentId, userName);
        return result;
    }

    /**
     * 查询机构评论列表  教育机构查询
     *
     * @param model
     * @return
     */
    @PostMapping("l/course-comment/list")
    RestResponse<PageVO> querryOrgCommentList(@RequestBody QuerryCommentModel model) {

        PageVO pageVO = commentService.querryCommentList(model,USEEnum.USE_ORGANI.getCode());

        return RestResponse.success(pageVO);
    }

    /**
     * 课程评论回复
     *
     * @param model
     * @return
     */
    @PostMapping("l/course-comment-reply")
    RestResponse<ReplyDTO> commentReply(@RequestBody ReplyModel model) {

        ReplyDTO replyDTO = commentService.commentReply(model);

        return RestResponse.success(replyDTO);
    }

    //删除评论
    @DeleteMapping("l/m/course-comment/{commentId}")
    RestResponse<Boolean> deleteCommentById(@PathVariable Long commentId) {

        Boolean result = commentService.deleteCommentById(commentId);

        return RestResponse.success(result);
    }

    //评论删除评论
    @DeleteMapping("/l/m/course-comment/batch-del/{commentIds}")
    RestResponse<Boolean> deleteComments(@PathVariable String[] commentIds) {

        Boolean result = commentService.deleteComments(commentIds);

        return RestResponse.success(result);
    }

    //查询所有机构评论,运营平台查询
    @PostMapping("l/m/course-comment/list-all")
    RestResponse<PageVO> querryOrgAllCommentList(@RequestBody QuerryCommentModel model){

        PageVO pageVO = commentService.querryCommentList(model,USEEnum.USE_AUDIT.getCode());

        return RestResponse.success(pageVO);
    }
}
